package com.ux.example
{
	import com.ux.control.DragBarHorizontal;
	import com.ux.event.DragBarEvent;
	import com.ux.manager.StageManager;
	import com.ux.util.BitmapUtil;
	import com.ux.util.MathUtil;
	
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	
	public class DragBarTest extends Sprite
	{
		
		private var dragBg : Sprite;
		private var dragBtn : MovieClip;
		
		private var bar : DragBarHorizontal;
		public function DragBarTest()
		{
			super();
			
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			StageManager.stage = this.stage;
			
			this.dragBtn = new MovieClip();
			this.dragBg = new Sprite();
			
			this.dragBtn.addChild( BitmapUtil.MakeBitmap( 40, 20, 0x000000 ) );
			this.dragBg.addChild( BitmapUtil.MakeBitmap( 1000, 400, 0x00ffcc ) );
			this.dragBg.addEventListener(MouseEvent.CLICK, onBgClick );
			this.dragBg.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel );
			this.addChild( dragBg );
			
			
			bar = new DragBarHorizontal();
			this.addChild( bar );
			bar.btnReSize( dragBg.width );
			
			bar.addEventListener(DragBarEvent.HORIZONTAL_UPDATE, onDragUpdate );
			
		}
		
		
		private function onMouseWheel( e:MouseEvent ):void 
		{
			if (e.delta < 0)
			{
				bar.btnMove( bar.x + 15 );
			}
			else
			{
				bar.btnMove( bar.x - 15 );
			}
		}
		
		private function onBgClick( e:MouseEvent ):void 
		{
			dragBg.width += 100;
			bar.btnReSize( dragBg.width );
			
//			StageManager.showDim();
//			Alert.show( "잘 보이나" );
		}
		
		
		private function onDragUpdate( e:DragBarEvent ):void 
		{
			this.dragBg.x = -MathUtil.RateToNumber( dragBg.width-bar.width, 0, e.dragValue );
		}
	}
}